package cn.pso.nspsofs;

import cn.knn.TestKNN;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

public class AllDataSet {

    public void getResult(String name) throws IOException {
//		List<String> choose = new ArrayList<String>();
//		for(int i=1;i<=ReadFile.getFeatureNum();i++){
//			choose.add(String.valueOf(i));
//		}
//		ReadFile rf = new ReadFile();
//		rf.getFile(choose, "TESTED\\Alltra--"+name, "Alltra--"+name);
//		rf.getFile(choose, "TESTED\\Alltest--"+name, "Alltest--"+name);


        File file = ResourceUtils.getFile("classpath:testfile\\all.dat");
        PrintWriter pw = new PrintWriter(new FileOutputStream(file, true));
//		Double accuracy = new TestKNN().runKnn("TESTED\\Alltra--"+name, "TESTED\\Alltest--"+name);

        String trafilePath = "dataset\\Alltra--" + name;
        String trafileAbsolutePath = ResourceUtils.getFile(trafilePath).getAbsolutePath();
        String testfilePath = "dataset\\Alltest--" + name;
        String testfileAbsolutePath = ResourceUtils.getFile(testfilePath).getAbsolutePath();
        double accuracy = new TestKNN().runKnn(trafileAbsolutePath, testfileAbsolutePath);
        double errorRate = 1 - accuracy;
        pw.write(name + ":" + errorRate);
        pw.write("\n");
        pw.flush();
        pw.close();
    }

    public static void main(String[] args) throws IOException {
//		new AllDataSet().getResult("BC");
//		new AllDataSet().getResult("german");
//		new AllDataSet().getResult("Hill_Valley");
//		new AllDataSet().getResult("ionosphere");
		new AllDataSet().getResult("vehicle");
//        new AllDataSet().getResult("wine");
//		new AllDataSet().getResult("zoo");
//		new AllDataSet().getResult("australian");
    }

}
